<?php

namespace Xmlib\Filament\Pages\Auth;

use Filament\Forms\Components\Component;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Auth\Login as BaseLogin;

class Login extends BaseLogin
{
    protected function getEmailFormComponent(): Component
    {
        return TextInput::make('email')
            ->label('用户名')
            ->placeholder('请输入用户名、手机号或电子邮箱')
            ->required()
            ->autofocus()
            ->extraInputAttributes(['tabindex' => 1]);
    }

    protected function getCredentialsFromFormData(array $data): array
    {
        return [
            'email' => function($query) use ($data) {
                $query->where('username', $data['email'])
                    ->orWhere('email', $data['email'])->orWhere('mobile', $data['email']);
            },
            'password' => $data['password'],
        ];
    }
}
